<?php namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Services\MatchService;
use App\Models\Catalog;
use App\Models\Area;
use App\Models\Match;

class MatchController extends Controller
{

    public function getIndex(MatchService $matchService, Request $request)
    {
        return view('admin.match.matchs', [
            'request' => $request,
            'p_catalogs' => Catalog::where(['p_id' => 0, 'level' => 1])->get(),
            'catalogs' => Catalog::where(['p_id' => $request->input('p_catalog_id'), 'level' => 2])->get(),
            'provinces' => Area::where(['p_id' => 0, 'level' => 1])->get(),
            'cities' => Area::where(['p_id' => $request->input('province_id'), 'level' => 2])->get(),
            'districts' => Area::where(['p_id' => $request->input('city_id'), 'level' => 3])->get(),
            'matchs' => $matchService->getList($request)
        ]);
    }

    public function getInfo($id)
    {
        return view('admin.match.match', [
            'match' => Match::find($id)
        ]);
    }

    public function getConfirm($id, MatchService $matchService)
    {
        $matchService->confirm($id);
        return $this->bSuccess('确认匹配成功', false, ['tabid' => 'matchs', 'dialogid' => 'match']);
    }

    public function getUnConfirm($id, MatchService $matchService)
    {
        $matchService->unConfirm($id);
        return $this->bSuccess('取消确认成功', false, ['tabid' => 'matchs', 'dialogid' => 'match']);
    }

    public function getDelete($id, MatchService $matchService)
    {
        $matchService->delete($id);
        return $this->bSuccess('删除匹配成功', false, ['tabid' => 'matchs']);
    }
}